'use strict'
angular.module('gkwb')
    .controller('MonitorCtrl', ['$scope', '$http','$interval', function($scope, $http,$interval) {

        function loadHealth(){
            $http.get('/actuator/health')
            .success(function(data) {
                $scope.health = data;

            })
        }

        function loadMetrics(){
            $http.get('/actuator/metrics')
            .success(function(data) {
                $scope.metrics = data;
                $scope.memPercent = Math.round(data['mem.free'] / data.mem * 100);
                $scope.heapPercent = Math.round(data['heap.used'] / data.heap * 100);
            })
        }

        function loadSignInfo(){
             $http.get('/view/admin/monitor/sign')
            .success(function(data){
                $scope.counter = data;
            })
            $http.get('/view/admin/monitor/sync')
                .success(function(data){
                    $scope.sync = data;
                    $scope.stuPercent = Math.round(data[0] / data[1] * 100);
                    $scope.orderPercent = Math.round(data[2] / data[3] * 100);
                })
        }
        
        $scope.refresh = function(){
            loadHealth();
            loadSignInfo();
            loadMetrics();
        }
       
        $scope.options = {
            animate: false,
            barColor: '#7266ba',
            scaleColor: false,
            lineWidth: 15,
            lineCap: 'butt'
        };

        loadHealth();
            loadSignInfo();
            loadMetrics();
    }])